#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""

@Time   :2025/8/6 上午9:59
@Author :zengjiahao1989@gmail.com
@File   :1.StrOutputParser.py
"""
import os

import dotenv
from langchain_core.output_parsers import StrOutputParser
# from langchain.schema.output_parser import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()
# 1 编排提示模版
prompt = ChatPromptTemplate.from_template("{query}")

# 2.构建大语言模型
llm = ChatOpenAI(
    model_name="kimi-k2-0711-preview",
    openai_api_key=os.getenv("OPENAI_API_KEY"),
    openai_api_base=os.getenv("OPENAI_API_BASE"),
)

# 3.创建字符串输出解析器
parser = StrOutputParser()
# content = parser.parse("哈哈哈哈巴")
#
# print(content)

# 4.调用大语言模型生成结果并解析

content = parser.invoke(llm.invoke(prompt.invoke({"query": "你好，你是？"})))

print(content)
